/*
 * CS_PVP_OUT_REQ.cpp
 *
 *  Created on: 2013. 5. 21.
 *      Author: the2
 */

#include "../../Command.h"

#include "../../User.h"
#include "../../NLogic/Space.h"
#include "../../NLogic/Battle.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_PVP_OUT_REQ(User * pUser, ::Network::Packet * pPacket)
{
/*	CS_PVP_OUT_REQ	0x0510
	{
		u32	user_seq;
	}
	SC_PVP_OUT_REQ	0x0511
	{
		s16	ack;	(1:정상종료, 1201:상대가 접속 종료)
		u32	user_Seq;
		u16	exit_map;
		u16	pos_x;
		u16	pos_y;
		u16	pos_degree;
	}*/

	PREPARE_PACKET;

	int userSeq	= 0;

	*pPacket >> userSeq;

	NLogic::Space * pSpace	= pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("CS_PVP_OUT_REQ : pSpace is NULL!!");
		return;
	}

	pSpace->LeaveUser(pUser);

	pUser->GetBattle()->GetData().x		= ConstPosX;
	pUser->GetBattle()->GetData().y		= ConstPosY;
	pUser->GetBattle()->GetData().degree = ConstDegree;
	pUser->GetBattle()->GetData().bReadyFight = false;
	pUser->GetBattle()->GetData().bRecvEnterRoom = false;

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	*pAck << static_cast<int16_t>(ACK_OK);
	*pAck << pUser->GetUserSeq();
	*pAck << static_cast<uint16_t>(1);			// exit_map_id(?)
	*pAck << static_cast<uint16_t>(pUser->GetBattle()->GetData().x);
	*pAck << static_cast<uint16_t>(pUser->GetBattle()->GetData().y);
	*pAck << static_cast<uint16_t>(pUser->GetBattle()->GetData().degree);

	pAck->MakePacket(CMD_SC_PVP_OUT_REQ);
	pUser->Send(pAck);
}

} /*NCommand*/ } /*ProjectZ*/
